#include <iconv.h>
#include <iostream>
#include "cliUtil.h"

using namespace std;

int main(int argc, char **argv)
{
   
    char in[] = "中文字符";
    char out1[MAX_CMD_LENGTH];
    char out2[MAX_CMD_LENGTH];

    // utf-8-->UNICODELITTLE
    CodeConverter cc1 = CodeConverter("utf-8","UNICODELITTLE");
    cc1.convert(in,strlen(in),out1,MAX_CMD_LENGTH);
    
    cout << "UTF8-->UNICODELITTLE in=[" << in << "][";
    for(unsigned i=0; i<strlen(in); i++)
    {
        printf("0x%hhx", in[i]);
        if(i!=(strlen(in)-1)) cout << ",";
    }
    
    cout << "], out=[" << out1 << "][" ;
    for(unsigned i=0; i<strlen(out1); i++)
    {
        printf("0x%hhx", out1[i]);
        if(i!=(strlen(out1)-1)) cout << ",";
    }
    cout <<  "]" << endl;

    // UNICODELITTLE-->utf-8
    CodeConverter cc2 = CodeConverter("UNICODELITTLE","utf-8");
    cc2.convert(out1,strlen(out1),out2,MAX_CMD_LENGTH);
    cout << "UNICODELITTLE-->UTF8 in=[" << out1 << "], out=[" << out2 << "]" << endl;


    string val;
    if(getCnString("sunny", val))
    {
        cout << "found UTF8 string in file strMap.txt:" << "[" << val.c_str() << "]" << endl;

        
        // UTF8-->UNICODELITTLE
        CodeConverter cc3 = CodeConverter("UNICODELITTLE","utf-8");
        cc3.convert(val.c_str(),val.length(),out1,MAX_CMD_LENGTH);
        cout << "UTF8-->UNICODELITTLE in=[" << val << "],out=[" << out1 << "]" << endl;
        
        for(unsigned i=0; i<strlen(out1); i++)
        {
            printf("0x%hhx", out1[i]);
            if(i!=(strlen(out1)-1)) cout << ",";
        }

        // UNICODELITTLE-->UTF8
        CodeConverter cc4 = CodeConverter("utf-8","UNICODELITTLE");
        cc4.convert(out1,strlen(out1),out2,MAX_CMD_LENGTH);
        cout << "UNICODELITTLE-->UTF8 in=[" << out1 << "], out=[" << out2 << "]" << endl;

    }
    else
    {
        cout << "found Nothing" << endl;
    }
}

